<?php
namespace app\common\model;

class PlanModel extends BaseModel
{
	protected $name = 'plan';

	const STATUS_NOT = 10;
	const STATUS_YET = 20;
	public static $status_list = [
		self::STATUS_NOT => '未支付',
		self::STATUS_YET => '已支付',
	];

	public static function get_status($value='')
	{
		if (empty($value)) return 0;
		$status_list = self::$status_list;
		$key = array_search($value, $status_list);

		return $key;
	}

	/**
	 * 按商品维度查询推广成交金额和成本
	 * @Author   zhibin3
	 * @DateTime 2022-10-20
	 * @param    array      $where [description]
	 * @param    integer    $page  [description]
	 * @param    integer    $limit [description]
	 * @param    string     $field [description]
	 * @return   [type]            [description]
	 */
	public function getStaticsByPerson(array $where, $page=1, $limit=10, $field='')
	{
		$pageList = $this->alias('pl')
					->join('tk_plan_person pp', 'pp.plan_id=pl.id', 'left')
					->join('tk_order o', 'o.order_sn=pl.order_sn', 'left')
					->join('tk_product pr', 'pr.product_code=o.product_code', 'left')
					->where($where)->field($field)
					->group('pr.id')->order('amount DESC')->paginate($limit);
		// echo $this->getLastSql();die;
		$pageList = json_decode(json_encode($pageList), true);

		return $pageList;
	}
}